socialsdk
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "socialsdk", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A SDK for Social -- The Internet's API", | ||
@@ -5,0 +5,0 @@ "main": "api.js", |
@@ -116,2 +116,99 @@ | ||
## Configuration | ||
- **API Base URL**: All requests are made relative to the `API_BASE_URL`, which should be configured to point to the Social backend server. | ||
- **API Key**: The module utilizes an `API_KEY` obtained from the environment variables for authorization. Ensure that `REACT_APP_API_KEY` is properly set in your environment. | ||
## Helper Function | ||
- **makeRequest**: A helper function designed to streamline the process of making API calls. It automatically appends the API key to the headers for authorization and handles the construction of the request based on the given endpoint, HTTP method, and data. | ||
## API Functions | ||
This section describes the key functions provided by the api.js module. | ||
### User Authentication | ||
- **login(email, password, platform_id)**: Authenticates a user against the platform. | ||
- **registerMember(name, email, user_id, password, platform_id)**: Registers a new member on the platform. | ||
### Content Management | ||
- **createPost(platform_id, memberId, contentType, content)**: Creates a new post on the platform. | ||
- **getPosts(member_id, platform_id)**: Fetches posts, optionally filtered by `member_id` or `platform_id`. | ||
- **uploadFile(file, platform_id)**: Uploads a file to the platform. | ||
- *Note: The front-end implementation for this method is marked as TODO.* | ||
### Social Interactions | ||
- **followUser(follower_id, followed_id)**: Initiates a follow relationship between two users. | ||
- **unfollowUser(follower_id, followed_id)**: Removes a follow relationship between two users. | ||
Platform and Member Management | ||
- **createPlatform(name)**: Creates a new platform within SocialSDK. | ||
- **addMemberToPlatform(platform_id, userId)**: Adds a member to a specified platform. | ||
- **getMembersOnPlatform(platform_id)**: Retrieves all members associated with a specific platform. | ||
- **deletePlatform(platform_id)**: Deletes a specified platform from SocialSDK. | ||
- **setPermissions(platform_id, contentType, allowed)**: Sets permissions for content posting on the platform. | ||
## Usage Examples | ||
### Logging in a User | ||
```jsx | ||
import { login } from './api'; | ||
const userEmail = 'user@example.com'; | ||
const userPassword = 'password123'; | ||
const platformId = 'platform1'; | ||
login(userEmail, userPassword, platformId) | ||
.then(response => console.log('Login Successful', response)) | ||
.catch(error => console.error('Login Failed', error)); | ||
``` | ||
### Registering a New Platform Member | ||
```jsx | ||
import { registerMember } from './api'; | ||
const memberInfo = { | ||
name: 'John Doe', | ||
email: 'john.doe@example.com', | ||
user_id: '1', // This is optional and to be adjusted based on backend requirements | ||
password: 'password123', | ||
platform_id: 'platform1' | ||
}; | ||
registerMember(memberInfo.name, memberInfo.email, memberInfo.user_id, memberInfo.password, memberInfo.platform_id) | ||
.then(response => console.log('Registration Successful', response)) | ||
.catch(error => console.error('Registration Failed', error)); | ||
``` | ||
## Advanced Topics | ||
- **Error Handling**: All functions are designed to propagate errors to the caller, allowing for sophisticated error handling strategies in the UI layer. | ||
- **Custom Headers**: While most requests will only require the API key, additional headers can be added to the `makeRequest` function as needed (e.g., content type for file uploads). | ||
## Future Enhancements | ||
- Expanding the API to cover more backend functionalities as they become available. | ||
- Improving error handling to provide more detailed feedback to the frontend. | ||
- Adding functionality to support real-time features like notifications or live updates. | ||
**Key API Method Cheatsheet:** | ||
- `login(email, password, platform_id)` | ||
- `registerMember(name, email, user_id, password, platform_id)` | ||
- `uploadFile(file, platform_id)` | ||
- `createPlatform(name)` | ||
- `addMemberToPlatform(platform_id, userId)` | ||
- `createPost(platform_id, memberId, contentType, content)` | ||
- `followUser(follower_id, followed_id)` | ||
- `unfollowUser(follower_id, followed_id)` | ||
- `getPosts(member_id, platform_id)` | ||
- `getMembersOnPlatform(platform_id)` | ||
## Components | ||
@@ -118,0 +215,0 @@ |
28550
286